﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>酒店管理-员工管理</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="assets/materialize/css/materialize.min.css" media="screen,projection" />
    <!-- Bootstrap Styles-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
    <!-- Morris Chart Styles-->
    <link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
    <!-- Custom Styles-->
    <link href="assets/css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="assets/js/Lightweight-Chart/cssCharts.css">
    <!-- Sweet Alert-->
    <link rel="stylesheet" href="assets/css/sweetalert2.min.css">
    <style>
        th,
        td {
            text-align: center
        }

        #btnzmx {
            margin-bottom: 20px;
            float: right;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <nav class="navbar navbar-default top-navbar" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle waves-effect waves-dark" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand waves-effect waves-dark" href="index.html">
                    <i class="large material-icons">track_changes</i>
                    <strong>Hotel Manage</strong>
                </a>

                <div id="sideNav" href="">
                    <i class="material-icons dp48">toc</i>
                </div>
            </div>

            <ul class="nav navbar-top-links navbar-right">
                <li>
                    <a class="dropdown-button waves-effect waves-dark" href="#!" data-activates="dropdown1">
                        <i class="fa fa-user fa-fw"></i>
                        <b id='admin'></b>
                        <i class="material-icons right">arrow_drop_down</i>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- Dropdown Structure -->
        <ul id="dropdown1" class="dropdown-content">
            <li>
                <a href="#">
                    <i class="fa fa-user fa-fw"></i> 个人中心</a>
            </li>
            <li>
                <a href="#">
                    <i class="fa fa-gear fa-fw"></i> 设置</a>
            </li>
            <li id='logoutBtn'>
                <a href="#">
                    <i class="fa fa-sign-out fa-fw"></i> 退出登录</a>
            </li>
        </ul>
        <!--/. NAV TOP  -->
        <!--/. NAV TOP  -->
        <nav class="navbar-default navbar-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">
                    <li>
                        <a class="waves-effect waves-dark" href="index.html">
                            <i class="fa fa-dashboard"></i> 首页</a>
                    </li>
                    <li>
                        <a href="employee.html" class="active-menu waves-effect waves-dark">
                            <i class="fa fa-desktop"></i> 员工管理</a>
                    </li>
                    <li>
                        <a href="room.html" class="waves-effect waves-dark">
                            <i class="fa fa-bar-chart-o"></i> 客房管理</a>
                    </li>
                    <li>
                        <a href="role.html" class="waves-effect waves-dark">
                            <i class="fa fa-qrcode"></i>角色管理</a>
                    </li>

                    <li>
                        <a href="user.html" class="waves-effect waves-dark">
                            <i class="fa fa-table"></i>用户管理</a>
                    </li>
                </ul>

            </div>

        </nav>
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper">
            <div class="header">
                <h1 class="page-header">
                    员工管理
                </h1>
                <ol class="breadcrumb">
                    <li>
                        <a href="#">主页</a>
                    </li>
                    <li>
                        <a href="#">用户管理 </a>
                    </li>
                    <li class="active">数据</li>
                </ol>

            </div>
            <div id="page-inner">
                <div id="btnzmx">
                    <a href="addEmployee.html" class="btn btn-info" id='tj'>添加员工</a>
                </div>
                <table class="table table-striped  table-bordered  table-hover" id="list" style="background: white;">
                    <tr>
                        <th style="background-color:#ccc">照片</th>
                        <th style="background-color:#ccc">编号</th>
                        <th style="background-color:#ccc">姓名</th>
                        <th style="background-color:#ccc">性别</th>
                        <th style="background-color:#ccc">年龄</th>
                        <th style="background-color:#ccc">电话</th>
                        <th style="background-color:#ccc">身份证号码</th>
                        <th style="background-color:#ccc">角色</th>
                        <th style="background-color:#ccc">操作</th>
                    </tr>
                </table>
                <!-- /. PAGE INNER  -->
            </div>
            <!-- /. PAGE WRAPPER  -->
        </div>
        <!-- /. WRAPPER  -->
        <!-- JS Scripts-->
        <!-- jQuery Js -->
        <script src="assets/js/jquery-1.10.2.js"></script>

        <!-- Bootstrap Js -->
        <script src="assets/js/bootstrap.min.js"></script>

        <script src="assets/materialize/js/materialize.min.js"></script>

        <!-- Metis Menu Js -->
        <script src="assets/js/jquery.metisMenu.js"></script>
        <!-- Morris Chart Js -->
        <script src="assets/js/morris/raphael-2.1.0.min.js"></script>
        <script src="assets/js/morris/morris.js"></script>


        <script src="assets/js/easypiechart.js"></script>
        <script src="assets/js/easypiechart-data.js"></script>

        <script src="assets/js/Lightweight-Chart/jquery.chart.js"></script>

        <!-- Custom Js -->
        <script src="assets/js/custom-scripts.js"></script>
        <script src="assets/js/public.js"></script>
        <!-- Sweet Alert -->
        <script src="assets/js/sweetalert2.min.js"></script>
        <script>
            //去后台拿到所有的员工信息
            $.ajax({
                url: 'employees',
                method: "GET",
                success: function (data) {
                    console.log(data)
                    //data就是后台传过来的那个数组,遍历数组,循环创建tr和td
                    $.each(data, function (index, value) {
                        $(`<tr>
                        <td><img src='assets/img/${value.photo}' style='width:80px;height:100px;border-radius:50px;'></td>
                        <td>${value.id}</td>
                        <td>${value.name}</td>
                        <td>${value.sex}</td>
                        <td>${value.age}</td>
                        <td>${value.phone}</td>
                        <td>${value.idCard}</td>
                        <td>${value.role}</td>
                        <td style="vertical-align:middle;">
                            <button class="btn btn-primary modify btn-block" rel="${value.id}">修改</button>
                            <br/>
                            <button class="btn btn-danger removeBtn btn-block" id="${value.id}">删除</button></td>
                        </tr>`).appendTo('table');
                    })

                }
            })

            $(document).on('click', '.removeBtn', function () {
                var id = this.id
                swal({
                    title: '您确定要删除吗?',
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确定删除',
                    cancelButtonText: '取消',
                    showLoaderOnConfirm: true,
                    preConfirm: function () {
                        return new Promise(function (resolve) {
                            $.ajax({
                                url: 'removeEmployee',
                                method: "POST",
                                data: `id=${id}`,
                                success: function (data) {
                                    if (data == 'success') {
                                        swal('删除成功', 'success').then(function(){
                                            location.reload()
                                        })
                                    }else{
                                        swal('删除失败', 'error');
                                    }
                                }
                            })
                        })
                    }
                })
            })

            $(document).on('click', '.modify', function () {
                location.href = 'addEmployee.html?id='+$(this).attr('rel');
            })
        </script>
</body>

</html>